#include "Solution.h"

solution initSolution(int vectorSize)
{
	solution s1;
	s1.x = (int*) malloc(sizeof(int)*vectorSize);
	s1.x_dim = vectorSize;
	s1.value = -1;
	s1.i = -1;
	s1.j = -1;
	s1.control = 0;
	
	return s1;
}

solution initSolutionWithParameters(int vectorSize, int* x_sol, int value_sol, int i_sol, int j_sol, int control_sol)
{
	solution s1 = initSolution(vectorSize);	
	setSolution(&s1, x_sol, value_sol, i_sol, j_sol, control_sol); 

	return s1;
}

void setSolution(solution* s1, int* x_sol, int value_sol, int i_sol, int j_sol, int control_sol)
{
	int i;
	s1->value = value_sol;
	s1->i = i_sol;
	s1->j = j_sol;
	if(x_sol == NULL) //if NULL we set by default a 0 vector
		for(i=0; i<s1->x_dim; i++)
			s1->x[i] = 0;
	else
		s1->x = x_sol;
}

int isSet(solution s1)
{
	return s1.control;
}

int isEqualOrLess(solution s1, solution s2)
{
	return (s1.value <= s2.value);
}

void showSolution(solution s1)
{
	int counter;
	printf("\n\n***PRINT SOLUTION***\n\n");
	if(s1.control == 0)
		printf("SOLUTION VECTOR NOT SETTED\n");
	
	printf("Element at row: %i \t column: %i\n", s1.i+1, s1.j+1); //for printing we use value + 1
	for(counter=0; counter < s1.x_dim; counter++)
		printf("x[%i] = %i\n",counter,s1.x[counter]);


	printf("Objective function value: %i\n",s1.value);
	printf("\n\n********************\n\n");
}

void showSolutionValue(solution s1)
{
	printf("%i",s1.value);
}